<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 class sessionController{
     private $nameSpace = "superadmin";
     public function getnameSpace(){
         return $this->nameSpace;
     }
     public function setBuyer(){
         $this->nameSpace='Buyer';
     }
     public function initialize($params){
         $setting = new Application_Model_DbTable_Settings();
         Zend_Session::start();
      
         $sessionController=new Zend_Session_Namespace($this->nameSpace);
         $sessionController->roleId =$params['roleId'];
         $sessionController->role =$params['role'];
         $sessionController->username = $params['username'];
         $sessionController->id=$params['id'];
         if($this->nameSpace=='Buyer'){
            $sessionController->setExpirationSeconds($setting->getSetting('pelanggan_timeout')); 
         }else{
            $sessionController->setExpirationSeconds($setting->getSetting('timeout'));
         }
         $sessionController->logId=$params['logId'];
         $sessionController->lock();//lock the session to readonly
     }
     public function checkSessionBuyer(){
         Zend_Session::start();
         
         $sessionController=new Zend_Session_Namespace('Buyer');
      //   return $sessionController->role;
         if((!isset($sessionController->username)&&
                 !isset($sessionController->role))||($sessionController->role !='buyer')){
             return false;
         }
         return $sessionController->role;
     }
     public function checkSessionAdmin($paramName){
         
         Zend_Session::start();
         $sessionController=new Zend_Session_Namespace($this->nameSpace);
        
         if(!isset($sessionController->username)&&
                 !isset($sessionController->role)){
             return false;
         }
         
         foreach($paramName as $param) :            
             if($sessionController->role == $param){
                 return true;
             }
         endforeach;
         return false;
     }
     public function checkSessionSuperAdmin(){

     }
     public function getSessionId(){
        Zend_Session::start();
        $sessionController=new Zend_Session_Namespace($this->nameSpace);
        if(isset($sessionController->id)){
            return $sessionController->id;
        }else{
            return 0;
        }
     }
     public function getSessionLogId(){
        Zend_Session::start();
        $sessionController=new Zend_Session_Namespace($this->nameSpace);
        return $sessionController->logId;
     }
     public function getSessionUsername(){
        Zend_Session::start();
        $sessionController=new Zend_Session_Namespace($this->nameSpace);
        return $sessionController->username;
     }
     public function getSessionRoleId(){
        Zend_Session::start();
        $sessionController=new Zend_Session_Namespace($this->nameSpace);
        return $sessionController->roleId;
     }
     public function getSessionRole(){
        Zend_Session::start();
        $sessionController=new Zend_Session_Namespace($this->nameSpace);
        return $sessionController->role;
     }
     public function logOut(){
        Zend_Session::start();
        $sessionController=new Zend_Session_Namespace($this->nameSpace);
         if($sessionController->isLocked()){
                $sessionController->unlock();
         }   
                $sessionController->resetSingleInstance($this->nameSpace);
                $sessionController->unsetAll();                
     }
 }
?>
